//
//  ViewController.m
//  ButtonAnimation
//
//  Created by Burn on 2019/8/20.
//  Copyright © 2019 menksoft. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 50, 50);
    btn.center = self.view.center;
    [self.view addSubview:btn];
    
    [btn setImage:[UIImage imageNamed:@"CloseButton"] forState:UIControlStateNormal];
   
    
    [btn addTarget:self action:@selector(touchBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    self.view.backgroundColor = [UIColor lightGrayColor];
}

- (void)touchBtn:(UIButton *)btn{
    [UIView animateWithDuration:.3 animations:^{
        btn.transform = CGAffineTransformRotate(btn.transform, M_PI);
    } completion:^(BOOL finished) {
        if ([btn.imageView.image isEqual:[UIImage imageNamed:@"CloseButton"]]) {
            [btn setImage:[UIImage imageNamed:@"locationButton"] forState:UIControlStateNormal];
        }else{
            [btn setImage:[UIImage imageNamed:@"CloseButton"] forState:UIControlStateNormal];
        }
    }];
    
    
}

@end
